<template>
  <div id="dialogposition">
    <el-form :model="userInfoData" :rules="userInfoRules" ref="userInfoDataForm" label-width="100px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="岗位名称：" prop="account">
            <el-input v-model="userInfoData.account" size="small" style="width:100%;"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="公司名称：" prop="password">
            <el-input v-model="userInfoData.password" disable size="small" style="width:100%;"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="工作地点：" prop="tel">
            <el-input v-model="userInfoData.tel" size="small" style="width:100%;"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="学历：" prop="email">
            <el-input v-model="userInfoData.email" size="small" style="width:100%;"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="备注：" prop="memo">
        <el-input type="textarea" :autosize="{ minRows: 3}" v-model="userInfoData.memo" size="small"
                  style="width:100%"></el-input>
      </el-form-item>
    </el-form>
    <div class="btn-box">
      <el-button type="info" size="large" @click="checkUserInfoData">保存</el-button>
      <el-button type="info" size="large" @click="cancelInfoEdit()">取消</el-button>
    </div>
  </div>
</template>
<script>
  import { postDataToServer } from '../../assets/js/post.js'
  import { formatterTime } from '../../assets/js/common.js'
  import { getStaticMapList } from '../../assets/js/GlobeDefine.js'

  export default {
    name: 'dialogposition',
    props: ['type', 'id'],
    data () {
      return {
        userInfoData: {
          id: '',
          account: '',
          password: '',
          verify_tel: 0,
          verify_email: 0,
          password: '',
          status: 0,
          memo: ''
        },
        userInfoRules: {
          account: [
            {min: 0, max: 60, message: '长度在 1 到 60 个字符', trigger: 'change', required: true}
          ],
          password: [
            {min: 0, max: 30, message: '长度在 1 到 30 个字符', trigger: 'change', required: true}
          ],
          memo: [
            {min: 0, max: 120, message: '长度在 1 到 120 个字符', trigger: 'change', required: true}
          ]
        },
        isDialog: false,
        page_no: 0
      }
    },
    created () {
      this.getCompanyData()
    },
    methods: {
      getCompanyData () {
        let _this = this
        let parameter = new Object()
        parameter.company_id = this.id
        postDataToServer('HM_RESUME_JOBS_GET', parameter).then((data) => {
          if (data.status === 0) {
            _this.userInfoData = data
            console.log(data)
          }
        })
      },
      checkUserInfoData () {
        let _this = this
        this.$refs['userInfoDataForm'].validate((valid) => {
          if (valid) {
            _this.saveUserInfoData()
          } else {
            this.$message({
              message: '存在数据填写错误！',
              type: 'error'
            })

          }
        })
      },
      saveUserInfoData () {
        let _this = this
        postDataToServer('HM_COMPANY_USER_EDIT', this.userInfoData).then((data) => {
          if (data.status === 0) {
            _this.isDialog = false
          } else {
            _this.$message.error(data.message)
          }
        })
      },
      cancelInfoEdit () {
        this.$emit('returnBack', false)
        for (let key in this.userInfoData) {
          this.userInfoData[key] = ''
        }
      },
    },
    watch: {
      isDialog (val, oldVal) {
        if (val === true) {
          this.getCompanyData()
        } else if (oldVal === false) {
          this.getCompanyDataList({'page_no': 1})
        }
      },
    }
  }
</script>
<style scoped>
  .btn-box {
    text-align: center;
  }
</style>
